package cn.xjt.IETcpServer;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author xujiangtao
 * @create 2020-08-05-10:20
 */
public class IEServer {
    public static void main(String[] args) throws IOException {
        ServerSocket server = new ServerSocket(8080);
        while (true)
        {
            Socket Ieclient = server.accept();
            new Thread(()->{
                try {

                    InputStream is = Ieclient.getInputStream();
            //        byte[] data = new byte[1024];
            //        int len = 0;
            //        while ((len=is.read(data))!=-1)
            //        {
            //            System.out.println("在循环");
            //            System.out.println(new String(data,0,len));
            //            System.out.println("while一次");
            //        }
                    System.out.println("循环完了");
                    BufferedReader bis =new BufferedReader(new InputStreamReader(is));
                    String line = bis.readLine();
                    System.out.println(line);
                    String[] str = line.split(" ");
                    String html = str[1].substring(1);
                    System.out.println(html+"\t###################");
                    FileInputStream fis = new FileInputStream(html);
                    System.out.println(html);
                    OutputStream os = Ieclient.getOutputStream();
                    os.write("HTTP/1.1 200 OK\r\n".getBytes());
                    os.write("Content-Type:text/html\r\n".getBytes());
                    os.write("\r\n".getBytes());
                    int len1 =0;
                    byte[] data1 = new byte[1024];
                    while ((len1=fis.read(data1))!=-1)
                    {
                        os.write(data1,0,len1);
                    }
                    System.out.println("结束");
                }catch (IOException e)
                {
                    System.out.println(e);
                }
            }).start();
        }


    }
}
